<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>上海泛软科技有限公司-后台登陆</title>
<meta name="robots" content="nofollow" />
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>
<link href="/Public/Css/admin-style.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.min.css" rel="stylesheet" type="text/css" />


<script language="javascript" type="text/javascript" src="/Public/Js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/admin-common.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.min.js"></script>
<!--<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.js"></script> -->
<script language="javascript" type="text/javascript" src="/Public/Js/rock_customer_list.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/demo.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/blob.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/FileSaver.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery.base64.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery-1.10.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/tableExport.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/xlsx.core.min.js"></script>
</head>

<body>


<style>
  #hedaer{
     background:#B9D3EE;
	 background-color:rgba(185,211,238,0.15);
	 width:100%;
	 height:120px;
	 border-bottom: 1px solid #ccc;
	 overflow:hidden ;
	 padding-left:15px;
	 padding-bottom:0px;
  }
  .select_Sty{
     float:left;
	 
  }
   .select_Sty select {
   width: 160px;
   padding: 2px;
   font-size: 14px;
   border: 1px solid #ccc;
   height: 23px;
   margin-right:20px;
   border-radius:3px
}
 .select_Sty input {
   width: 160px;
   padding: 2px;
   font-size: 12px;
   border: 1px solid #ccc;
   height: 23px;
   margin-right:20px;
   border-radius:3px
}
 #content #boder{
    padding-left:10px;
	padding-right:10px;
   
 }
 body{
   background-color:rgba(232,232,232,0.25);
 }
 h4{
    font-size: 14px;
	margin-bottom:0px;
 }
 h5{
    font-size: 10px;
 }
 
</style>
<div id="background"> 
 
 <div id="hedaer">
   <h4 id="fileName">设备报警</h4>
   <div class="select_Sty">
   <h5>设备编号:</h5>
    <!-- <select class="se" name="d_number">
	  <option value ="请选择">请选择</option>
	<?php if(is_array($dev_no)): $i = 0; $__LIST__ = $dev_no;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$dev_no): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($dev_no['d_number']); ?>"><?php echo ($dev_no['d_number']); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>	
    </select> -->
	<input type="type" class="device_no"  name="d_number" id="dev_no" placeholder="请输入设备编号"></input>
   </div>
   <div class="select_Sty">
   <h5>设备标识:</h5>
	<input type="type" class="dev_nanme"  name="d_name" id="dev_nanme" placeholder="请输入设备标识"></input>
   
   </div>	
   <div class="select_Sty">
   <h5>所属医院:</h5>
    <select class="se" name="h_name">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($hospital)): $i = 0; $__LIST__ = $hospital;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$hospital): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($hospital['name']); ?>"><?php echo ($hospital['name']); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>	
    </select>
   </div>	
    <div class="select_Sty">
     <h5>设备类型:</h5>
    <select class="se" name="d_style">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($dev_sty)): $i = 0; $__LIST__ = $dev_sty;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$dev_sty): $mod = ($i % 2 );++$i;?><option value="<?php echo ($dev_sty[0]); ?>"><?php echo ($dev_sty['d_style']); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
    </select>
   </div>
   <div class="select_Sty">
     <h5>最后上传日期:</h5>
	 <input type="date" name="0" id="date" class="se"></input>
   </div>
   <div class="select_Sty">
     <h5>状态:</h5>
    <select class="se" name="d_status">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($dev_status)): $i = 0; $__LIST__ = $dev_status;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$dev_status): $mod = ($i % 2 );++$i;?><option value="<?php echo ($dev_status[0]); ?>"><?php echo ($dev_status['d_status']); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
    </select>
   </div>
  
   <div id="search" style="margin-left:230px;margin-top:50px">
    <button type="button"  class="btn btn-primary btn-sm" onclick="search()">查询</button>
   </div>
 </div>   
 <div id="content">
   <div id="boder">
    <div id="items" class="listd" style="width:90%;float:left;">
     <p><span id="cou">加载中...</span></p> 
   </div>
    <div style="width:10%;float:left;">
		 <ul style="float:left;font-weight:bold;">
		   <!-- <li class="listd" style="float:left;margin:2px"><a href="#" id="" data-toggle="modal" data-target="#myModal1">编辑</a></li> -->
		   <li  class="listd" style="float:left;margin:2px"><a id="modify" href="<?php echo U('');?>" >修改</a></li>
		   <li  class="listd" style="float:left;margin:2px"><a id="equitment_delete" >删除</a></li>
           <li  class="listd" style="float:left;margin:2px"><a id="device_Export">导出</a></li>
		  		
		</ul>
     </div>
	<table class="table table-bordered deviceTblae" style="background:white">
	  <thead style="background-color:rgba(232,232,232,0.35)">
		<tr>
		  <th style="text-align:center"><input class="all_choose" type="checkbox"></input></th>
		  <th style="text-align:left">设备编号</th>
		  <th style="text-align:left">设备标识</th>
		  <th style="text-align:left">所属医院</th>
		  <th style="text-align:left">设备类型</th>
		  <th style="text-align:left">最后上传用户</th>
		  <th style="text-align:right">最后上传日期</th>
		  <th style="text-align:right">设备状态</th>
		  <th style="text-align:right">备注</th>
		</tr>
	  </thead>
	  <tbody id="equipment_AData">
	  </tbody>
	</table>
	<ul class="pagination" id = "fenye" style="float:right;margin:0px">
    </ul>
	
   </div>
 </div>
</div>
<script>
  localStorage.eqString = 0;		
  initData(0,0);
  var flagSum = 0;
  function initData(num,pagenum){
    //加载设备数据
	$.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/equipment_Alarm_initData',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   str:num,
		   pageNum:pagenum
		 },
 	     success: function(obj){
		 var data = obj.data;
		
          debugger;		 
          var html='';
		  for(var i = 0; i < data.length; i++){
            html+=		   
		   '<tr>'
		    +'<td style="text-align:center"><input u_id='+data[i]["u_id"]+' d_id='+data[i]["d_id"]+' h_id='+data[i]["h_id"]+' class="choose" type="checkbox"></input></td>'
		    +'<td style="text-align:left">'+data[i]["d_number"]+'</td>'
		    +'<td style="text-align:left">'+data[i]["d_name"]+'</td>'
		    +'<td style="text-align:left">'+data[i]["h_name"]+'</td>'
		    +'<td style="text-align:left">'+data[i]["d_style"]+'</td>'
		    +'<td style="text-align:left">'+data[i]["u_realname"]+'</td>'
		    +'<td style="text-align:right">'+data[i]["update_time"]+'</td>'
		    +'<td style="text-align:right">'+data[i]["d_status"]+'</td>'
		    +'<td style="text-align:right">等待处理</td>'
		    +'</tr>'
		  }
           document.getElementById("equipment_AData").innerHTML = html;
          
		   localStorage.sumCount = obj.count; 
		   if(flagSum != localStorage.sumCount){
		     fenyeFun();
			 flagSum = localStorage.sumCount;
			 //总数据个数
			  document.getElementById("cou").innerHTML = localStorage.sumCount;
		   }
           //单选
		  $(".choose").click(function(){
		   var all_choose = $(".all_choose").is(':checked');
		   if(all_choose){
		  	  $(".all_choose").prop('checked',false);
			 }
		   });
		 }
	   });
  }
 //全选
  $(".all_choose").click(function(){
    var flag = $(this).is(':checked');
	if(flag){
      $(".choose").each(function(){
      $(this).prop('checked',true);
    })
	}else{
	  $(".choose").each(function(){
		 $(this).prop('checked',false);
	   })
	 }
  })
  
  //删除
  document.getElementById("equitment_delete").onclick = function(){
    var len = $("input[type='checkbox']:checked").length;//删除用户的个数
	if(len == 0){
	   alert("请选择需要删除的设备");
	}else{
	  var d_arr = new Array();
	  $(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
			d_arr.push($(this).attr("d_id"));
	     }		
	   })
      var string1 = JSON.stringify(d_arr);//将数组转为json
	  $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/equip_delete',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   destr:string1
		 },
 	     success: function(data){
		  alert(data);
		  location.reload(true);                                     
		 }
	   });
     }
  }
  //
 
  //修改
  document.getElementById("modify").onclick = function(){
    var len = $("input[type='checkbox']:checked").length;//修改数据的个数
    if(len == 0){
	   alert("请选择修改的用户");
	   return false;
	 }else if(len!=1){
	   alert("每次只能修改一个用户数据");
	   return false;
	 }
	var t_id = '';
	var h_id = '';
	var dp_id = '';
	$(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
		    h_id = $(this).attr("h_id");
			d_id = $(this).attr("d_id");
			u_id = $(this).attr("u_id");
		}		
	}) 
	if(h_id == "无" || d_id== "无" || u_id == "无"){
	  alert("该设备不能修改");
	  return false;
	}
	var url = "<?php echo U('equipment_Alarm_Modify');?>";
	url = url+"?h_id="+h_id+"&"+"d_id="+d_id+"&"+"u_id="+u_id;
	document.getElementById("modify").href = url;
  }
 //查询
 function search(){//dev_nanme
   var arr = {};
   var device_no = $(".device_no").val();
   if(device_no != ''){
     var name = $(".device_no").attr("name");
	 var name1 = name.substr(0,1);
	 name = name1+"."+name;
	 arr[name] = device_no; 
   }
   var dev_nanme = $(".dev_nanme").val();
   if(dev_nanme != ''){
   var name = $(".dev_nanme").attr("name");
	 var name1 = name.substr(0,1);
	 name = name1+"."+name;
	 arr[name] = dev_nanme; 
   }
   $(".se").each(function(){
	  var value = $(this).val();
	  if($(this).val()!="请选择"){
		var name = $(this).attr("name");
		var name1 = name.substr(0,1);
		name = name1+"."+name;
		arr[name] = value; 
	  }
    });
  var dd = arr["0.0"];
  var string = JSON.stringify(arr);//将数组转为json
  var leng = string.length;
  if(leng == 10 && dd ==""){
    initData(0,0);
  }else{
    initData(string,1);
	localStorage.eqString = string; 
  }
  
}
 var now = new Date();
 var str_now = now.getFullYear() + "-" + fix((now.getMonth() + 1),2) + "-" + fix(now.getDate(),2);
// document.getElementById('date').value= str_now;//给结束时间赋值
 function fix(num, length) {
   return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num;
 }
 //获取日期与时间
 function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
	var hours = date.getHours(); //获取当前小时数(0-23)
    var min =  date.getMinutes(); //获取当前分钟数(0-59)
    var second = date.getSeconds(); //获取当前秒数(0-59)
	
    if (month >= 1 && month <= 9) {
         month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
	if(hours >=0 && hours <= 9){
	   hours = "0" + hours;
	}
	if(min >=0 && min <= 9){
	   min = "0" + min;
	}
	if(second >=0 && second <= 9){
	   second = "0" + second;
	}
    var currentdate = year + seperator1 + month + seperator1 + strDate +" "+hours +"时" + min+"分" + second+"秒";
    return currentdate;
 } 
 $("#fenye").on("click","li",function(){
     $("li").attr("class","");
	 $(this).attr("class","active");
 })
 //分页数据
 function fenyeFun(){
   var htmlfen = '';
   if(localStorage.sumCount>=1){   
	htmlfen +='<li class="active fen" page="1"><a href="#">首页</a></li>'
    var pages=Math.ceil(localStorage.sumCount/20);
    for (var i =1; i <= pages;i++){
        htmlfen += '<li class="fen" page='+i+'><a href="#">'+i+'</a></li>'
    }
	var pageEnd = pages+1;
        htmlfen += ' <li class="fen" i='+pageEnd+' page='+pages+'><a href="#">末页</a></li>'
    }
	$("#fenye").html(htmlfen);
		$(".fen").each(function(){
		$(this).on("click",function(){
			var applipage=$(this).attr("page");
		    initData(localStorage.eqString,applipage);
		});
	  
	});
 }
 //导出exce
 var exportData = document.getElementById("device_Export");
 exportData.onclick = function(){
    //$(".deviceTblae").tableExport({ type: 'excel', separator: ';', escape: 'false' });
	var fName = $("#fileName").html();
	var currentTime =  getNowFormatDate();
	fName = fName+'_'+currentTime;
	$(".deviceTblae").tableExport({ type: 'excel', separator: ',', escape: 'false',fileName:fName });
 }
</script>

</body>
</html>